// 应用设置模块

const state = {
  // 侧边栏折叠状态
  sidebarCollapsed: false,
  // 应用设置
  settings: {
    theme: 'default', // 主题
    language: 'zh_CN', // 语言
    showTags: true, // 是否显示标签导航
    fixedHeader: true // 是否固定头部
  }
}

const getters = {
  sidebarCollapsed: state => state.sidebarCollapsed,
  settings: state => state.settings
}

const mutations = {
  // 切换侧边栏状态
  TOGGLE_SIDEBAR(state) {
    state.sidebarCollapsed = !state.sidebarCollapsed
  },
  // 设置侧边栏状态
  SET_SIDEBAR_COLLAPSED(state, collapsed) {
    state.sidebarCollapsed = collapsed
  },
  // 更新应用设置
  UPDATE_SETTING(state, { key, value }) {
    if (state.settings.hasOwnProperty(key)) {
      state.settings[key] = value
    }
  },
  // 重置应用设置
  RESET_SETTINGS(state) {
    state.settings = {
      theme: 'default',
      language: 'zh_CN',
      showTags: true,
      fixedHeader: true
    }
  }
}

const actions = {
  // 切换侧边栏
  toggleSidebar({ commit }) {
    commit('TOGGLE_SIDEBAR')
  },
  // 设置侧边栏状态
  setSidebarCollapsed({ commit }, collapsed) {
    commit('SET_SIDEBAR_COLLAPSED', collapsed)
  },
  // 更新设置
  updateSetting({ commit }, payload) {
    commit('UPDATE_SETTING', payload)
  },
  // 重置设置
  resetSettings({ commit }) {
    commit('RESET_SETTINGS')
  }
}

export default {
  namespaced: true,
  state,
  getters,
  mutations,
  actions
} 